﻿function FileHandler(File) {
    var Width = 30;
    var Height = 30;
    var Top = (window.screen.availHeight - 100 - Height) / 2;
    var Left = (window.screen.availWidth - 220 - Width) / 2;
    window.open(File, 'DownLoadFile', 'height=' + Height + ',,innerHeight=' + Height + ',width=' + Width + ',innerWidth=' + Width + ',top=' + Top + ',left=' + Left + ',toolbar=no,menubar=no,scrollbars=auto,resizeable=yes,location=no,status=no');
}

function custom_close() {
    if (confirm("您确定要关闭本页吗？")) {
        window.opener = null;
        window.open('', '_self');
        window.close();
    }
    else { }
}

function JSInfomation(info, IsCloseForm) {
    alert(info);

    //是否关闭窗口
    if (IsCloseForm) {
        window.close();
    }
}

function Submit_PreCallBack(button) {
    if (!confirm('Are you sure to submit it?')) {
        return false;
    }

    button.style.display = 'none';
    DeleteDiv();
    return true;
}

function ScrollMessageDiv(p) {
    var d = document, w = window, o = d.getElementById(p.id), ie6 = /msie 6/i.test(navigator.userAgent);
    if (o) {
        o.style.cssText += ";position:" + (p.f && !ie6 ? 'fixed' : 'absolute') + ";" + (p.r ? 'left' : "right") + ":0;" + (p.t != undefined ? 'top:' + p.t + 'px' : 'bottom:0');
        if (!p.f || ie6) {
-function () {
    var t = 500, st = d.documentElement.scrollTop || d.body.scrollTop, c;
    c = st - o.offsetTop + (p.t != undefined ? p.t : (w.innerHeight || d.documentElement.clientHeight) - o.offsetHeight);
    c != 0 && (o.style.top = o.offsetTop + Math.ceil(Math.abs(c) / 10) * (c < 0 ? -1 : 1) + 'px', t = 10);
    setTimeout(arguments.callee, t)
} ()
        }
    }
}

function ShowMessage(htmlvalue, count) {

    if (document.getElementById("divMes")) DeleteDiv();
    var PRINT_A = document.getElementById("PRINT_A");

    var div_box = document.createElement('DIV');
    div_box.id = 'divMes';
    div_box.style.position = 'absolute';
    var w = PRINT_A.offsetWidth;
    var h = PRINT_A.offsetHeight - (count * 28);

    div_box.style.left = (PRINT_A.offsetWidth + 12) + "px";
    div_box.style.top = "0px";
    div_box.style.width = '240px';
    div_box.style.background = '#FFFFFF';
    div_box.style.visibility = 'visible';

    div_box.innerHTML = "<div style='border:solid 1px Orange;padding:6px 10px 10px 0px; margin:6px 0px 10px 0px; font-size:12px; color:#000000;'>" + htmlvalue + "</div>";
    document.body.appendChild(div_box);

    ScrollMessageDiv({ id: 'divMes', t: 0 });
}

function DeleteDiv() {
    try {
        var div = document.getElementById('divMes');
        div.parentNode.removeChild(div);

    } catch (e) {
    }
}

function PrintView(ID) {
    //var sprnhtml = document.getElementById(ID).outerHTML;
    //var selfhtml = window.document.body.innerHTML;//获取当前页的html

    //window.document.body.innerHTML = sprnhtml;
    window.print();
    //window.document.body.innerHTML=selfhtml;

    //局部打印后，当前页面打印区域外的操作都不好用了，所采用了当执行打印时重新刷新页面
    //window.location.reload(); 
}

function winOpenPopup(strURL, str_width, str_height, str_value, str_element, str_postback, str_multiple) {
    try {
        var var_time = new Date();
        var winoption = "dialogWidth=" + (parseInt(str_width) + 18) + "px;dialogHeight=" + str_height + "px;dialogLeft: status:no; directories:yes;scrollbars:auto;Resizable=yes;";
        var tmp = window.showModalDialog(strURL + "&vt=" + var_time, '', winoption);

        if (tmp != null && tmp != "" && tmp != undefined) {
            var o = eval('(' + tmp + ')');

            //是否多选
            if (str_multiple == "0") {
                document.getElementById(str_element).value = eval("o." + str_value);
            } else {
                document.getElementById(str_element).value = document.getElementById(str_element).value + eval("o." + str_value) + ",";
            }

            //是否Postback
            if (str_postback == "1") {
                document.getElementById(str_element).onchange();
                //Anthem_FireCallBackEvent(this,event,str_element,'',false,'','','',true,null,null,null,true,true);
                //__doPostBack(str_element,"change:"  + document.getElementById(str_element).value);
            }
        }
    } catch (e) {
    }
}

/**
* Calendar
* @param   beginYear           1990
* @param   endYear             2010
* @param   language            0(zh_cn)|1(en_us)|2(en_en)|3(zh_tw)|4(jp)
* @param   patternDelimiter    "-"
* @param   date2StringPattern  "yyyy-MM-dd"
* @param   string2DatePattern  "ymd"
*/
function Calendar(beginYear, endYear, language, patternDelimiter, date2StringPattern, string2DatePattern) {
    this.beginYear = beginYear || 1990;
    this.endYear = endYear || 2020;
    this.language = language || 0;
    this.patternDelimiter = patternDelimiter || "-";
    this.date2StringPattern = date2StringPattern || Calendar.language["date2StringPattern"][this.language].replace(/\-/g, this.patternDelimiter);
    this.string2DatePattern = string2DatePattern || Calendar.language["string2DatePattern"][this.language];

    this.dateControl = null;
    this.panel = this.getElementById("__calendarPanel");
    this.iframe = window.frames["__calendarIframe"];
    this.form = null;

    this.date = new Date();
    this.year = this.date.getFullYear();
    this.month = this.date.getMonth();

    this.colors = { "bg_cur_day": "#A9E3A6", "bg_over": "#F0F7E8", "bg_out": "#FFCC00" }
};

Calendar.language = {
    "year": ["\u5e74", "", "", "\u5e74", "\u5e74"],
    "months": [
				["\u4e00\u6708", "\u4e8c\u6708", "\u4e09\u6708", "\u56db\u6708", "\u4e94\u6708", "\u516d\u6708", "\u4e03\u6708", "\u516b\u6708", "\u4e5d\u6708", "\u5341\u6708", "\u5341\u4e00\u6708", "\u5341\u4e8c\u6708"],
				["JAN", "FEB", "MAR", "APR", "MAY", "JUN", "JUL", "AUG", "SEP", "OCT", "NOV", "DEC"],
				["JAN", "FEB", "MAR", "APR", "MAY", "JUN", "JUL", "AUG", "SEP", "OCT", "NOV", "DEC"],
				["\u4e00\u6708", "\u4e8c\u6708", "\u4e09\u6708", "\u56db\u6708", "\u4e94\u6708", "\u516d\u6708", "\u4e03\u6708", "\u516b\u6708", "\u4e5d\u6708", "\u5341\u6708", "\u5341\u4e00\u6708", "\u5341\u4e8c\u6708"],
				["\u4e00\u6708", "\u4e8c\u6708", "\u4e09\u6708", "\u56db\u6708", "\u4e94\u6708", "\u516d\u6708", "\u4e03\u6708", "\u516b\u6708", "\u4e5d\u6708", "\u5341\u6708", "\u5341\u4e00\u6708", "\u5341\u4e8c\u6708"]
				],
    "weeks": [["\u65e5", "\u4e00", "\u4e8c", "\u4e09", "\u56db", "\u4e94", "\u516d"],
				["Sun", "Mon", "Tur", "Wed", "Thu", "Fri", "Sat"],
				["Sun", "Mon", "Tur", "Wed", "Thu", "Fri", "Sat"],
				["\u65e5", "\u4e00", "\u4e8c", "\u4e09", "\u56db", "\u4e94", "\u516d"],
				["\u65e5", "\u6708", "\u706b", "\u6c34", "\u6728", "\u91d1", "\u571f"],
			],
    "clear": ["\u6e05\u7a7a", "Clear", "Clear", "\u6e05\u7a7a", "\u524a\u9664"],
    "today": ["\u4eca\u5929", "Today", "Today", "\u4eca\u5929", "\u4eca\u65e5"],
    "close": ["\u5173\u95ed", "Close", "Close", "\u95dc\u9589", "\u623b\u308b"],
    "date2StringPattern": ["yyyy-MM-dd", "yyyy-MM-dd", "yyyy-MM-dd", "yyyy-MM-dd", "yyyy-MM-dd"],
    "string2DatePattern": ["ymd", "ymd", "ymd", "ymd", "ymd"]
};

Calendar.prototype.draw = function () {
    calendar = this;

    var _cs = [];
    _cs[_cs.length] = '<form id="__calendarForm" name="__calendarForm" method="post">';
    _cs[_cs.length] = '<table id="__calendarTable" width="100%" border="0" cellpadding="3" cellspacing="1" align="center">';
    _cs[_cs.length] = ' <tr>';
    _cs[_cs.length] = '  <th><input class="l" name="goPrevMonthButton" type="button" id="goPrevMonthButton" value="&lt;" \/><\/th>';
    _cs[_cs.length] = '  <th colspan="5"><select class="year" name="yearSelect" id="yearSelect"><\/select><select class="month" name="monthSelect" id="monthSelect"><\/select><\/th>';
    _cs[_cs.length] = '  <th><input class="r" name="goNextMonthButton" type="button" id="goNextMonthButton" value="&gt;" \/><\/th>';
    _cs[_cs.length] = ' <\/tr>';
    _cs[_cs.length] = ' <tr>';
    for (var i = 0; i < 7; i++) {
        _cs[_cs.length] = '<th class="theader">';
        _cs[_cs.length] = Calendar.language["weeks"][this.language][i];
        _cs[_cs.length] = '<\/th>';
    }
    _cs[_cs.length] = '<\/tr>';
    for (var i = 0; i < 6; i++) {
        _cs[_cs.length] = '<tr align="center">';
        for (var j = 0; j < 7; j++) {
            switch (j) {
                case 0: _cs[_cs.length] = '<td class="sun">&nbsp;<\/td>'; break;
                case 6: _cs[_cs.length] = '<td class="sat">&nbsp;<\/td>'; break;
                default: _cs[_cs.length] = '<td class="normal">&nbsp;<\/td>'; break;
            }
        }
        _cs[_cs.length] = '<\/tr>';
    }
    _cs[_cs.length] = ' <tr>';
    _cs[_cs.length] = '  <th colspan="2"><input type="button" class="b" name="clearButton" id="clearButton" \/><\/th>';
    _cs[_cs.length] = '  <th colspan="3"><input type="button" class="b" name="selectTodayButton" id="selectTodayButton" \/><\/th>';
    _cs[_cs.length] = '  <th colspan="2"><input type="button" class="b" name="closeButton" id="closeButton" \/><\/th>';
    _cs[_cs.length] = ' <\/tr>';
    _cs[_cs.length] = '<\/table>';
    _cs[_cs.length] = '<\/form>';

    this.iframe.document.body.innerHTML = _cs.join("");
    this.form = this.iframe.document.forms["__calendarForm"];

    this.form.clearButton.value = Calendar.language["clear"][this.language];
    this.form.selectTodayButton.value = Calendar.language["today"][this.language];
    this.form.closeButton.value = Calendar.language["close"][this.language];

    this.form.goPrevMonthButton.onclick = function () { calendar.goPrevMonth(this); }
    this.form.goNextMonthButton.onclick = function () { calendar.goNextMonth(this); }
    this.form.yearSelect.onchange = function () { calendar.update(this); }
    this.form.monthSelect.onchange = function () { calendar.update(this); }

    this.form.clearButton.onclick = function () { calendar.dateControl.value = ""; calendar.hide(); }
    this.form.closeButton.onclick = function () { calendar.hide(); }
    this.form.selectTodayButton.onclick = function () {
        var today = new Date();
        calendar.date = today;
        calendar.year = today.getFullYear();
        calendar.month = today.getMonth();
        calendar.dateControl.value = today.format(calendar.date2StringPattern);
        calendar.hide();
    }
};

Calendar.prototype.bindYear = function () {
    var ys = this.form.yearSelect;
    ys.length = 0;
    for (var i = this.beginYear; i <= this.endYear; i++) {
        ys.options[ys.length] = new Option(i + Calendar.language["year"][this.language], i);
    }
};

Calendar.prototype.bindMonth = function () {
    var ms = this.form.monthSelect;
    ms.length = 0;
    for (var i = 0; i < 12; i++) {
        ms.options[ms.length] = new Option(Calendar.language["months"][this.language][i], i);
    }
};

Calendar.prototype.goPrevMonth = function (e) {
    if (this.year == this.beginYear && this.month == 0) { return; }
    this.month--;
    if (this.month == -1) {
        this.year--;
        this.month = 11;
    }
    this.date = new Date(this.year, this.month, 1);
    this.changeSelect();
    this.bindData();
};

Calendar.prototype.goNextMonth = function (e) {
    if (this.year == this.endYear && this.month == 11) { return; }
    this.month++;
    if (this.month == 12) {
        this.year++;
        this.month = 0;
    }
    this.date = new Date(this.year, this.month, 1);
    this.changeSelect();
    this.bindData();
};

Calendar.prototype.changeSelect = function () {
    var ys = this.form.yearSelect;
    var ms = this.form.monthSelect;
    for (var i = 0; i < ys.length; i++) {
        if (ys.options[i].value == this.date.getFullYear()) {
            ys[i].selected = true;
            break;
        }
    }
    for (var i = 0; i < ms.length; i++) {
        if (ms.options[i].value == this.date.getMonth()) {
            ms[i].selected = true;
            break;
        }
    }
};

Calendar.prototype.update = function (e) {
    this.year = e.form.yearSelect.options[e.form.yearSelect.selectedIndex].value;
    this.month = e.form.monthSelect.options[e.form.monthSelect.selectedIndex].value;
    this.date = new Date(this.year, this.month, 1);
    this.changeSelect();
    this.bindData();
};

Calendar.prototype.bindData = function () {
    var calendar = this;
    var dateArray = this.getMonthViewDateArray(this.date.getFullYear(), this.date.getMonth());
    var tds = this.getElementsByTagName("td", this.getElementById("__calendarTable", this.iframe.document));
    for (var i = 0; i < tds.length; i++) {
        tds[i].style.backgroundColor = calendar.colors["bg_over"];
        tds[i].onclick = null;
        tds[i].onmouseover = null;
        tds[i].onmouseout = null;
        tds[i].innerHTML = dateArray[i] || "&nbsp;";
        if (i > dateArray.length - 1) continue;
        if (dateArray[i]) {
            tds[i].onclick = function () {
                if (calendar.dateControl) {
                    calendar.dateControl.value = new Date(calendar.date.getFullYear(),
														calendar.date.getMonth(),
														this.innerHTML).format(calendar.date2StringPattern);
                }
                calendar.hide();
            }
            tds[i].onmouseover = function () { this.style.backgroundColor = calendar.colors["bg_out"]; }
            tds[i].onmouseout = function () { this.style.backgroundColor = calendar.colors["bg_over"]; }
            var today = new Date();
            if (today.getFullYear() == calendar.date.getFullYear()) {
                if (today.getMonth() == calendar.date.getMonth()) {
                    if (today.getDate() == dateArray[i]) {
                        tds[i].style.backgroundColor = calendar.colors["bg_cur_day"];
                        tds[i].onmouseover = function () { this.style.backgroundColor = calendar.colors["bg_out"]; }
                        tds[i].onmouseout = function () { this.style.backgroundColor = calendar.colors["bg_cur_day"]; }
                    }
                }
            }
        } //end if		
    } //end for
};

Calendar.prototype.getMonthViewDateArray = function (y, m) {
    var dateArray = new Array(42);
    var dayOfFirstDate = new Date(y, m, 1).getDay();
    var dateCountOfMonth = new Date(y, m + 1, 0).getDate();
    for (var i = 0; i < dateCountOfMonth; i++) {
        dateArray[i + dayOfFirstDate] = i + 1;
    }
    return dateArray;
};

Calendar.prototype.show = function (dateControl, popuControl) {
    if (this.panel.style.display == "block") {
        this.panel.style.display = "none";
    }
    if (!dateControl) {
        throw new Error("arguments[0] is necessary!")
    }
    this.dateControl = dateControl;
    popuControl = popuControl || dateControl;

    this.draw();
    this.bindYear();
    this.bindMonth();
    if (dateControl.value.length > 0) {
        this.date = new Date(dateControl.value.toDate(this.patternDelimiter, this.string2DatePattern));
        this.year = this.date.getFullYear();
        this.month = this.date.getMonth();
    }
    this.changeSelect();
    this.bindData();

    var xy = this.getAbsPoint(popuControl);
    this.panel.style.left = xy.x + "px";
    this.panel.style.top = (xy.y + dateControl.offsetHeight) + "px";
    this.panel.style.display = "block";
};

Calendar.prototype.hide = function () {
    this.panel.style.display = "none";

    //added by zk 2010-03-09
    if (this.dateControl != undefined
	&& this.dateControl.attributes["ct-type"] != undefined
	&& this.dateControl.attributes["ct-type"].value == "Calender") {
        try {
            this.dateControl.onchange = function () { eval(this.attributes["onblur2"].value); };
            this.dateControl.onchange();
        } catch (exception)
       { }
    }
};

Calendar.prototype.getElementById = function (id, object) {
    object = object || document;
    return document.getElementById ? object.getElementById(id) : document.all(id);
};

Calendar.prototype.getElementsByTagName = function (tagName, object) {
    object = object || document;
    return document.getElementsByTagName ? object.getElementsByTagName(tagName) : document.all.tags(tagName);
};

Calendar.prototype.getAbsPoint = function (e) {
    var x = e.offsetLeft;
    var y = e.offsetTop;
    while (e = e.offsetParent) {
        x += e.offsetLeft;
        y += e.offsetTop;
    }
    return { "x": x, "y": y };
};

/**
* @param   d the delimiter
* @param   p the pattern of your date
* @author  meizz
* @author  kimsoft add w+ pattern
*/
Date.prototype.format = function (style) {
    var o = {
        "M+": this.getMonth() + 1, //month
        "d+": this.getDate(),      //day
        "h+": this.getHours(),     //hour
        "m+": this.getMinutes(),   //minute
        "s+": this.getSeconds(),   //second
        "w+": "\u65e5\u4e00\u4e8c\u4e09\u56db\u4e94\u516d".charAt(this.getDay()),   //week
        "q+": Math.floor((this.getMonth() + 3) / 3),  //quarter
        "S": this.getMilliseconds() //millisecond
    }
    if (/(y+)/.test(style)) {
        style = style.replace(RegExp.$1, (this.getFullYear() + "").substr(4 - RegExp.$1.length));
    }
    for (var k in o) {
        if (new RegExp("(" + k + ")").test(style)) {
            style = style.replace(RegExp.$1, RegExp.$1.length == 1 ? o[k] : ("00" + o[k]).substr(("" + o[k]).length));
        }
    }

    return style;
};

/**
* @param d the delimiter
* @param p the pattern of your date
* @rebuilder kimsoft
* @version build 2006.12.15
*/
String.prototype.toDate = function (delimiter, pattern) {
    delimiter = delimiter || "-";
    pattern = pattern || "ymd";
    var a = this.split(delimiter);
    var y = parseInt(a[pattern.indexOf("y")], 10);
    //remember to change this next century ;)
    if (y.toString().length <= 2) y += 2000;
    if (isNaN(y)) y = new Date().getFullYear();
    var m = parseInt(a[pattern.indexOf("m")], 10) - 1;
    var d = parseInt(a[pattern.indexOf("d")], 10);
    if (isNaN(d)) d = 1;
    return new Date(y, m, d);
};

var divs = [];
divs[divs.length] = '<div id="__calendarPanel" style="margin-left:3px;position:absolute;display:none;background-color:#FFFFFF;border:1px solid #666666;width:200px;height:204px;">';
divs[divs.length] = '<iframe name="__calendarIframe" id="__calendarIframe" width="100%" height="100%" scrolling="no" frameborder="0" style="margin:0px;"><\/iframe>';
divs[divs.length] = '<\/div>';
document.write(divs.join(""));

var __ci = window.frames['__calendarIframe'];
var cis = [];
cis[cis.length] = '<!DOCTYPE html PUBLIC "-\/\/W3C\/\/DTD XHTML 1.0 Transitional\/\/EN" "http:\/\/www.w3.org\/TR\/xhtml1\/DTD\/xhtml1-transitional.dtd">';
cis[cis.length] = '<html xmlns="http:\/\/www.w3.org\/1999\/xhtml">';
cis[cis.length] = '<head>';
cis[cis.length] = '<meta http-equiv="Content-Type" content="text\/html; charset=utf-8" \/>';
cis[cis.length] = '<title>Web Calendar(UTF-8)<\/title>';
cis[cis.length] = '<style type="text\/css">';
cis[cis.length] = '<!--';
cis[cis.length] = 'body {font-size:12px;margin:0px;text-align:center;}';
cis[cis.length] = 'form {margin:0px;}';
cis[cis.length] = 'select {font-size:12px;background-color:#A9E3A6;}';
cis[cis.length] = 'table {border:0px solid #FFFFFF;background-color:#FFFFFF}';
cis[cis.length] = 'th {font-size:12px;font-weight:normal;background-color:#A9E3A6;height:16px;}';
cis[cis.length] = 'th.theader {font-weight:normal;background-color:#A9E3A6;color:#757575;width:22px;font-weight:bold;}';
cis[cis.length] = 'select.year {width:64px;font-size:12px;border-style:none;color:#FFFFFF;}';
cis[cis.length] = 'select.month {width:60px;font-size:12px;border-style:none;color:#FFFFFF;}';
cis[cis.length] = 'td {font-size:12px;text-align:center;}';
cis[cis.length] = 'td.sat {color:#0000FF;background-color:#EFEFEF;}';
cis[cis.length] = 'td.sun {color:#FF0000;background-color:#EFEFEF;}';
cis[cis.length] = 'td.normal {background-color:#A9E3A6;}';
cis[cis.length] = 'input.l {border:1px solid #A9E3A6;background-color:#A9E3A6;width:20px;height:17px;color:#FFFFFF;}';
cis[cis.length] = 'input.r {border:1px solid #A9E3A6;background-color:#A9E3A6;width:20px;height:17px;color:#FFFFFF;}';
cis[cis.length] = 'input.b {border:1px solid #A9E3A6;background-color:#A9E3A6;width:100%;height:17px;color:#FFFFFF;}';
cis[cis.length] = '-->';
cis[cis.length] = '<\/style>';
cis[cis.length] = '<\/head>';
cis[cis.length] = '<body>';
cis[cis.length] = '<\/body>';
cis[cis.length] = '<\/html>';
__ci.document.writeln(cis.join(""));
__ci.document.close();
var calendar = new Calendar();


// jquery clone存在bug
(function (original) {
    jQuery.fn.clone = function () {
        var result = original.apply(this, arguments),
            my_textareas = this.find('textarea').add(this.filter('textarea')),
            result_textareas = result.find('textarea').add(result.filter('textarea')),
            my_selects = this.find('select').add(this.filter('select')),
            result_selects = result.find('select').add(result.filter('select'));

        for (var i = 0, l = my_textareas.length; i < l; ++i) $(result_textareas[i]).val($(my_textareas[i]).val());
        for (var i = 0, l = my_selects.length; i < l; ++i) result_selects[i].selectedIndex = my_selects[i].selectedIndex;

        return result;
    };
})(jQuery.fn.clone);

function closeWin() {
    try {
        window.opener.reload();
    } catch(err) {
    }
    window.opener = null;
    window.open('', '_self');
    window.close();
}


/*
 * jQuery tableGroup plugin
 * Version: 0.1.0
 *
 * Copyright (c) 2007 Roman Weich
 * http://p.sohei.org
 *
 * Dual licensed under the MIT and GPL licenses 
 * (This means that you can choose the license that best suits your project, and use it accordingly):
 *   http://www.opensource.org/licenses/mit-license.php
 *   http://www.gnu.org/licenses/gpl.html
 *
 * Changelog: 
 * v 0.1.0 - 2007-05-20
 */

(function ($) {
    var defaults = {
        groupColumn: 1,
        useNumChars: 0,
        groupClass: ''
    };

    /**
     * Returns the cell element which has the passed column index value.
     * @param {element} table    The table element.
     * @param {array} cells        The cells to loop through.
     * @param {integer} col    The column index to look for.
     */
    var getCell = function (table, cells, col) {
        for (var i = 0; i < cells.length; i++) {
            if (cells[i].realIndex === undefined) //the test is here, because rows/cells could get added after the first run
            {
                fixCellIndexes(table);
            }
            if (cells[i].realIndex == col) {
                return cells[i];
            }
        }
        return null;
    };

    /**
     * Calculates the actual cellIndex value of all cells in the table and stores it in the realCell property of each cell.
     * Thats done because the cellIndex value isn't correct when colspans or rowspans are used.
     * Originally created by Matt Kruse for his table library - Big Thanks! (see http://www.javascripttoolbox.com/)
     * @param {element} table    The table element.
     */
    var fixCellIndexes = function (table) {
        var rows = table.rows;
        var len = rows.length;
        var matrix = [];
        var cols = 0;
        for (var i = 0; i < len; i++) {
            var cells = rows[i].cells;
            var clen = cells.length;
            cols = Math.max(clen, cols);
            for (var j = 0; j < clen; j++) {
                var c = cells[j];
                var rowSpan = c.rowSpan || 1;
                var colSpan = c.colSpan || 1;
                var firstAvailCol = -1;
                if (!matrix[i]) {
                    matrix[i] = [];
                }
                var m = matrix[i];
                // Find first available column in the first row
                while (m[++firstAvailCol]) {
                }
                c.realIndex = firstAvailCol;
                for (var k = i; k < i + rowSpan; k++) {
                    if (!matrix[k]) {
                        matrix[k] = [];
                    }
                    var matrixrow = matrix[k];
                    for (var l = firstAvailCol; l < firstAvailCol + colSpan; l++) {
                        matrixrow[l] = 1;
                    }
                }
            }
        }
        table.numCols = cols;
    };

    /**
     * Simple grouping of rows in a table.
     *
     * @param {map} options            An object for optional settings (options described below).
     *
     * @option {integer} groupColumn        The column to group after.
     *                            Index starting at 1!
     *                            Default value: 1
     * @option {string} groupClass        A CSS class that is set on the inserted grouping row.
     *                            Default value: ''
     * @option {integer} useNumChars        Defines the number of characters that are used to group the rows together. Set it to 0 to use all characters.
     *                            Default value: 0
     *
     * @example $('#table').tableGroup();
     * @desc Group the rows using the default settings.
     *
     * @example $('#table').tableGroup({groupColumn: 3, groupClass: 'mygroups', useNumChars: 1});
     * @desc Group the rows after the first character in the third column. Set the CSS class "mygroups" to all inserted rows.
     *
     * @type jQuery
     *
     * @name tableGroup
     * @cat Plugins/tableGroup
     * @author Roman Weich (http://p.sohei.org)
     */
    $.fn.tableGroup = function (options) {
        var settings = $.extend({}, defaults, options);

        return this.each(function () {
            var tboI, rowI, gC, body, row, $row, lastIH, c, cStr, match, tc;
            gC = settings.groupColumn - 1;
            lastIH = '';
            if (!this.tBodies || !this.tBodies.length) {
                return;
            }
            cStr = 'tGroup ' + settings.groupClass;
            //loop through the bodies
            for (tboI = 0; tboI < this.tBodies.length; tboI++) {
                body = this.tBodies[tboI];
                //loop through the rows
                for (rowI = 0; rowI < body.rows.length; rowI++) {
                    row = body.rows[rowI];
                    c = getCell(this, row.cells, gC);
                    if (c) {
                        if (settings.useNumChars == 0) {
                            match = c.innerHTML;
                        }
                        else {
                            tc = c.textContent || c.innerText;
                            match = tc.substr(0, settings.useNumChars);
                        }
                        if (match !== lastIH) {
                            //insert grouping row
                            $row = $('<tr class="' + cStr + '"><td colspan="' + this.numCols + '"><span>' + match + '</span></td></tr>');
                            $row.find('td')[0].realIndex = 0;
                            $(row).before($row);
                            lastIH = match;
                        }
                    }
                }
            }
        });
    };

    /**
     * Removes the grouping rows from the table.
     *
     * @type jQuery
     *
     * @name tableUnGroup
     * @cat Plugins/tableGroup
     * @author Roman Weich (http://p.sohei.org)
     */
    $.fn.tableUnGroup = function () {
        return this.each(function () {
            $('tr.tGroup', this).remove();
        });
    };
})(jQuery);


(function ($) {
    $.fn.serializeJson = function () {
        var serializeObj = {};
        $(this.serializeArray()).each(function () {
            serializeObj[this.name] = this.value;
        });
        return serializeObj;
    };
})(jQuery);
